<?php

define('IN_PROJECTOR', true);//用于防止模块文件被直接运行
define('S_ROOT', dirname(dirname(__FILE__)).'/');//网站根目录常量
error_reporting(E_ERROR | E_WARNING | E_PARSE);//Debug
set_magic_quotes_runtime(0);//魔法括号
set_time_limit(0);
require_once './core/version.inc.php';

//类自动加载
function __autoload($classname){
	if(substr($classname, 0, 8) != 'PHPExcel'){
		require_once './model/'.$classname.'.class.php';
	}
}

//公用函数
require_once './core/global.func.php';

//初始化一个自定义的全局变量，用于存储用户信息，缓存信息等等
$_G = array();

//程序配置及关键信息
$PHP_SELF = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
$_G['setting'] = (include './data/config.inc.php') + (include './data/stconfig.inc.php');
$_G['setting']['db'] = include './data/dbconfig.inc.php';
$_G['root_url'] = htmlspecialchars('http://'.$_SERVER['HTTP_HOST'].preg_replace("/\/+(api|archiver|wap)?\/*$/i", '', substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'))).'/');//网站根路径，可用于邮件发送中的验证链接等等
$_G['style'] = &$_G['setting']['style'];
empty($_G['style']) && $_G['style'] = 'default';

//数据库配置
$_G['db'] = new Mysql();
$db = &$_G['db'];
$tpre = $_G['setting']['db']['tpre'];
$db->set_tablepre($tpre);
$db->connect($_G['setting']['db']['server'], $_G['setting']['db']['user'], $_G['setting']['db']['pw'], $_G['setting']['db']['name'], $_G['setting']['db']['pconnect']);

//时间戳
if(PHP_VERSION > '5.1') {
	@date_default_timezone_set('Etc/GMT +'.intval($_G['setting']['timezone']));
}

$_G['timestamp'] = time() + intval($_G['setting']['timefix']);
$mtime = explode(' ', microtime());
$_G['starttime'] = $mtime[1] + $mtime[0];

if($_GET['confirm']){
	$_SERVER['HTTP_REFERER'] = $_COOKIE['http_referer'];
	rsetcookie('http_referer');
	if(!empty($_GET['confirm_key'])){
		$_POST = unserialize($_COOKIE['postdata_'.$_GET['confirm_key']]);
		rsetcookie('postdata_'.$_GET['confirm_key']);
	}
}
foreach(array('_POST', '_GET', '_COOKIE') as $request){
	${$request} = rhtmlspecialchars(raddslashes(${$request}));
}

//当使用手机登录时，手机模式$_G['mobile_mode']定义为true
if($_GET['mobile'] == 'no'){
	rsetcookie('mobile');

}elseif($_GET['mobile'] == 'yes' || $_COOKIE['mobile'] == 'yes'){
	$_G['mobile_mode'] = true;
	$_G['style'] = '3g';
	rsetcookie('mobile', 'yes');

}else{
	$mobilebrowser_list = array('iphone', 'android', 'phone', 'mobile', 'wap', 'netfront', 'java', 'opera mobi', 'opera mini','ucweb', 'windows ce', 'symbian', 'series', 'webos', 'sony', 'blackberry', 'dopod', 'nokia', 'samsung','palmsource', 'xda', 'pieplus', 'meizu'
	, 'midp', 'cldc', 'motorola', 'foma', 'docomo', 'up.browser','up.link', 'blazer', 'helio', 'hosin', 'huawei', 'novarra', 'coolpad', 'webos', 'techfaith', 'palmsource','alcatel', 'amoi', 'ktouch', 'nexian', 'ericsson', 'philips', 'sagem', 'wellcom', 'bunjalloo', 'maui', 'smartphone','iemobile', 'spice', 'bird', 'zte-', 'longcos', 'pantech', 'gionee', 'portalmmm', 'jig browser', 'hiptop','benq', 'haier', '^lct', '320x320', '240x320', '176x220');
	$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
	foreach($mobilebrowser_list as $mb){
		if(strpos($useragent, $mb) !== false){
			$_G['mobile_mode'] = true;
			$_G['style'] = '3g';
			rsetcookie('mobile', 'yes');
			break;
		}
	}
}
isset($_G['mobile_mode']) || $_G['mobile_mode'] = false;

//用户自动登录
$_G['admin'] = new Admin();
if($_COOKIE['rcuserinfo']){
	$_G['admin']->login($_COOKIE['rcuserinfo']);
}

//常用变量处理
$navtitle = '';
$page = max(1, intval($_GET['page']));
?>
